Membedah direktory .git
git merupakkan salah satu version control system. git sendiri menyimpan datanya yang berada pada directory .git.
sebenarnya apa yang ada didalam directory tersebut..
ketika git diinisialisasi, kira kira seperti ini isianya
.
├── .git
│ ├── branches
│ ├── COMMIT_EDITMSG
│ ├── config
│ ├── description
│ ├── HEAD
│ ├── hooks
│ │ ├── applypatch-msg.sample
│ │ ├── commit-msg.sample
│ │ ├── fsmonitor-watchman.sample
│ │ ├── post-update.sample
│ │ ├── pre-applypatch.sample
│ │ ├── pre-commit.sample
│ │ ├── pre-merge-commit.sample
│ │ ├── prepare-commit-msg.sample
│ │ ├── pre-push.sample
│ │ ├── pre-rebase.sample
│ │ ├── pre-receive.sample
│ │ ├── push-to-checkout.sample
│ │ ├── sendemail-validate.sample
│ │ └── update.sample
│ ├── index
│ ├── info
│ │ └── exclude
│ ├── logs
│ │ ├── HEAD
│ │ └── refs
│ │ └── heads
│ │ ├── develop
│ │ └── master
│ ├── objects
│ │ ├── 0a
│ │ │ └── 5568b3eb72786b7d025f317905c26d9b2a59ce
│ │ ├── 14
│ │ │ └── fe9524a16b1d8857b59dfb0d0f8c8c0042e6fb
│ │ ├── 19
│ │ │ └── 36cc1d441e479bc8fb17da77ec6f06e477f286
│ │ ├── a1
│ │ │ └── 1732bd3a69d1a74c7d2cc43fe5e8e306cfb2b8
│ │ ├── c1
│ │ │ └── 2636e1080859de32e8fc5c7b40e3890e9dcb96
│ │ ├── e6
│ │ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│ │ ├── info
│ │ └── pack
│ └── refs
│ ├── heads
│ │ ├── develop
│ │ └── master
│ └── tags
└── index.html
20 directories, 32 files
sekarang mari bedah satu persatu bagaimana git bekerja.
refs directory
pertama yaitu folder refs, folder ini berisi id commit HEAD disetiap branch. ketika ada commit baru disuatu branch, maka isi file yang terdapat di folder .git/refs/heads/<branch> ini akan diupdate dengan id commit yang baru.
HEAD file
file ini berisi referece id commit yang sedang aktif pada branch yang aktif.
misal saat ini developer berada pada branch develop, maka reference ini akan berada pada refs/branch tersebut
ref: refs/heads/develop
path tersebut merupakan path dimana id commit HEAD berada
hooks directory
folder hooks berisi sebuah script pada lifecycle git. setiap script file pada folder hook akan dijalankan disetiap lifecycle pada git
misal didalam folder hook terdapat file pre-commit. file ini akan dijalankan sebelum commit benar benar dijalankan
logs directory
folder logs berisi history commit untuk setiap branch. historynya akan disimpan pada .git/logs/refs/heads/<file dengan nama branch>
coba kita ambil pada file branch main, isinya sperti ini
0000000000000000000000000000000000000000 14fe9524a16b1d8857b59dfb0d0f8c8c0042e6fb user <example@mail.com> 1725529404 +0700 commit (initial): welcome to the world
kolom pertama(yang berisi 0000000000000000000000000000000000000000, atau biasa disebut None ) merupakan id commit parent. ketika membuat commit baru, maka semua logs pada branch main akan dicommit ke branch develop. seperti ini
0000000000000000000000000000000000000000 14fe9524a16b1d8857b59dfb0d0f8c8c0042e6fb user <example@mail.com> 1725529435 +0700 branch: Created from master
14fe9524a16b1d8857b59dfb0d0f8c8c0042e6fb c12636e1080859de32e8fc5c7b40e3890e9dcb96 user <example@mail.com> 1725531077 +0700 commit: add conten index
dan jika terdapat commit baru maka akan dibuat id commit baru dan mengambil id commit parent dari commit sebelumnya
dan ada juga .git/logs/refs/stash, file ini sebagai history stash.
ketika menjalankan perintah git stash -m "message", maka akan dicatat pada file ini
untuk folder .git/logs/refs/remotes/origin/ sama halnya dengan folder .git/logs/refs/heads/. folder ini menyimpan history/log commit. bedanya hanya yaitu heads untuk local sedangkan remotes untuk logs yang berada pada remote seperti github/gitlab
Additional
worktree directory
folder worktree ini untuk menyimpan data data git seperti yang ada di folder .git, namun data di worktree ini hanya terbatas pada data terpenting, sepeti logs, heads, commit_editmsg yang terakhir
Reference: